<?php
	//include("../connect/connect_dsccmis.php");
	// procedure ก่อนหน้า คือ 
	// สร้าง mis_temp_viewlosofper
	/*$sql = "drop table if exists mis_temp_viewlosofper;";
	$rs=mysql_query($sql);
	$sql = "create table mis_temp_viewlosofper as select evnid,concat(rolplcidgen,rolvllnogen) as plcidgen,losbody,sex,regnme,perid,nme,surnme,losbodynme from mis_viewlosofper where concat(rolplcidgen,rolvllnogen) <> '00000000'";
	$rs=mysql_query($sql);
		// procedure ก่อนหน้า คือ 
		// mis_temp_viewlosofper
		// create_gis_event.php-->gis_event   เพื่อให้ได้ cdscc , mis_evntypid
	// create index
	$sql="CREATE INDEX evnid_index USING BTREE ON mis_temp_viewlosofper (evnid);CREATE INDEX plcidgen_index USING BTREE ON mis_temp_viewlosofper (plcidgen);CREATE INDEX evnid_index USING BTREE ON gis_event(evnid);";
	$rs=mysql_query($sql);*/
	//เหยื่อ    ----- query ช้ามากๆ  น่าจะ index gis_event
	$sql = "drop table if exists gis_victim;";
	$rs=mysql_query($sql);
    $sql="create table gis_victim as  select concat(t1.rolplcidgen,t1.rolvllnogen) as rolplcidgen,left(t1.rolplcidgen,2) as prov,t1.evnid,t4.evndte,t4.cdscc,t4.mis_evntypid,t1.losbody,mis_losbody,sex,regnme,perid,nme,surnme,t1.losbodynme,t3.vill_name,tam_name,amp_name,
prov_name,t3.lat,t3.lng,perupddte from mis_viewlosofper t1
 inner join convert_losbody t2 on t1.losbody=t2.losbody left join convert_latlngofsouthprov t3
on concat(t1.rolplcidgen,t1.rolvllnogen)=t3.vill_code inner join gis_event t4 on t1.evnid=t4.evnid";
// where concat(t1.rolplcidgen,t1.rolvllnogen) <> '00000000'
	$rs=mysql_query($sql);
	//mysql_close($c);
	echo "<br>complete create gis_victim on dsccmis";
?>